const workerScript = `
    self.onmessage = ({data})=>{
        const view = new Uint32Array(data);
        for(let i=0; i<1e6; i++){
            // 线程不安全加操作，会导致资源争用
            view[0]+=1
        }
        self.postMessage(null);
    }
`

const workerBlobUrl = URL.createObjectURL(new Blob([workerScript]))

// 创建容量为4的工作线程池

const workers = []
for (let i = 0; i < 4; i++) {
    workers.push(new Worker(workerBlobUrl))
}

// 在最后一个工作线程完成后打印出最终值
let resCount = 0
for (const worker of workers) {
    worker.onmessage = () => {
        if (++resCount === workers.length) {
            console.log(view[0]);
        }
    }
}

console.log(crossOriginIsolated);

// 初始化shaderArrayBuffer
const shaderArrayBuffer = new SharedArrayBuffer(4)
const view = new Uint32Array(shaderArrayBuffer)
view[0] = 1
console.log(view);